import { defineStore } from 'pinia';
import defaultSettings from '@/settings';

const { sideTheme } = defaultSettings;
interface storageSetting {
  sideTheme?:string;
  showMoreSide?: boolean;
}
interface Data {
  key:string;
  value:string|boolean;
}
interface AppState {
  title?: string;
  sideTheme: string|boolean;
  showMoreSide: string|boolean;
  pageType: string;
}
const storageLocal:any = localStorage.getItem('layout-setting')
const storageSetting:storageSetting = JSON.parse(storageLocal);

export const useSettingsStore = defineStore({
  id: 'settings', // id必填，且需要唯一
  state: (): AppState => {
    return {
      title: '',
      sideTheme: storageSetting?.sideTheme || sideTheme,
      showMoreSide: storageSetting?.showMoreSide || false,
      pageType: ''
    };
  },
  actions: {
    // 修改布局设置
    changeSetting(data:Data) {
      const { key, value }:{ key:string, value:string|boolean } = data;
      if (key==='sideTheme') {
        this.sideTheme = value;
      } else {
        this.showMoreSide = value;
      }
    },
    changePageType(pageType:string) {
      this.pageType = pageType;
    }
  },
});
